package com.feicheng.controller.wx;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.feicheng.common.result.ResultInfo;
import com.feicheng.service.IFRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.feicheng.persistence.entity.Record;

import javax.xml.transform.Result;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cailongyang
 * @since 2022-01-10
 */
@RestController("/wx/record")
@RequestMapping("/wx/record")
public class RecordController {

    @Autowired
    IFRecordService recordService;

    @PostMapping("/info")
    public ResultInfo newRecord(Record record, String buildFilesJsonString) {

        JSONArray imgUrls = JSON.parseArray(buildFilesJsonString);
        record.setStatu(true);
        record.setDFlg(false);

        return ResultInfo.success(recordService.newRecord(record, imgUrls));
    }

    @GetMapping("/info")
    public ResultInfo getRecordByCarInfo(String tel, String carNumber, String vin) {
        return recordService.getRecordByCarInfo(tel, carNumber, vin);
    }

    @GetMapping("/info/{id}")
    public ResultInfo getRecordById(@PathVariable(name="id") Integer recordId) {
        return recordService.getRecordById(recordId);
    }

}
